#include <algorithm>
#include <cstring>
#include <cstdio>

using namespace std;

const int maxn = 100010;
const int mank = 1010;

struct Person {
	char name[10];
	int age;
	int worth;
}per[maxn], valid[maxn];

bool cmp(Person a, Person b) {
	if (a.worth != b.worth) {
		return a.worth > b.worth;
	} else if (a.age != b.age) {
		return a.age < b.age;
	} else {
		return strcmp(a.name, b.name) < 0;
	}
}

int main() {
	int n, k;
	int num, ageL, ageR;
	scanf("%d%d", &n, &k);
	for (int i = 0; i < n; i++) {
		scanf("%s%d%d", per[i].name, &per[i].age, &per[i].worth);
	}
	sort(per, per+n, cmp);
	for (int i = 0; i < k; i++) {
		scanf("%d%d%d", &num, &ageL, &ageR);
		printf("Case #%d:\n", i+1);
		int printNum = 0;
		for (int j = 0; printNum < num && j < n; j++) {
			if (per[j].age >= ageL && per[j].age <= ageR) {
				printf("%s %d %d\n", per[j].name, per[j].age, per[j].worth);
				printNum++;
			}
		}
		if (printNum == 0) {
			printf("None\n");
		}
	}


	return 0;
}










